﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess.DataObject;

namespace DataAccess.BusinessObject
{
    public class BProduct_Meta:Common.CDBase
    {
        /// <summary>
        /// Thêm meta value
        /// </summary>
        /// <param name="IDProduct"></param>
        /// <param name="MetaKey"></param>
        /// <param name="MetaValue"></param>
        /// <returns></returns>
        public bool Add(int IDProduct, string MetaKey,string MetaValue)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct",SqlDbType.Int),
                                        new SqlParameter("@MetaKey",SqlDbType.VarChar),
                                        new SqlParameter("@MetaValue",SqlDbType.NVarChar)};
            sqlParam[0].Value = IDProduct;
            sqlParam[1].Value = MetaKey;
            sqlParam[2].Value = MetaValue;
            return RunProcedure("sp_tblProduct_Meta_add", sqlParam);
        }
        public bool Delete(int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int) };
            sqlParam[0].Value = IDProduct;
            return RunProcedure("sp_tblProduct_Meta_delete", sqlParam);
        }
        public bool Delete(int IDProduct,string MetaKey)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int),
                                        new SqlParameter("@MetaKey",SqlDbType.VarChar)};
            sqlParam[0].Value = IDProduct;
            sqlParam[1].Value = MetaKey;
            return RunProcedure("sp_tblProduct_Meta_delete", sqlParam);
        }
        /// <summary>
        /// Đếm số meta
        /// </summary>
        /// <param name="IDProduct"></param>
        /// <returns></returns>
        public int CountProduct(int IDProduct,string MetaKey)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int),
                                        new SqlParameter("@MetaKey",SqlDbType.VarChar)};
            sqlParam[0].Value = IDProduct;
            sqlParam[1].Value = MetaKey;
            DataTable dtb = RunProcedureGet("sp_tblProduct_Meta_count", sqlParam);
            return int.Parse(dtb.Rows[0]["Count"].ToString());
        }
        public IList<OProduct_Meta> Get(int IDProduct,string MetaKey)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int),
                                        new SqlParameter("@MetaKey",SqlDbType.VarChar)};
            sqlParam[0].Value = IDProduct;
            sqlParam[1].Value = MetaKey;
            return Common.Common.ConvertTo<OProduct_Meta>(RunProcedureGet("sp_tblProduct_Meta_get", sqlParam));
        }
    }
}
